home *** CD-ROM | disk | FTP | other *** search
/ Zen & the Art of Resourc…The BMUG Guide to ResEdit / Zen and the Art of Resource Editing - The BMUG Guide to ResEdit (1995).iso / ResEdit 2.1.3 / Examples / CExamples / Source / ICON.Pick.c < prev    next >
C/C++ Source or Header  |  1994-07-15  |  5KB  |  146 lines

  1. /*
  2.  COPYRIGHT (C) 1984-1990 Apple Computer,Inc.
  3.  All rights reserved
  4. */
  5.  
  6. /* Icon Resource Picker */
  7.  
  8. /*    This is the Icon resource picker example.
  9.         The general scheme is that a List structure is created whose cells
  10.         contain the ID's of this resource type.  A drawproc is installed in the List
  11.         record which is called to display the resource. */
  12.  
  13. #include    <types.h>
  14. #include    <memory.h>
  15. #include    <menus.h>
  16. #include    <resources.h>
  17. #include    <lists.h>
  18.  
  19. #include    "ResEd.h"
  20.  
  21. #define iconMenuID 10            /* Just one of ResEdit's menus. */
  22. #define listCellSizeH             0x38
  23. #define listCellSizeV                0x42
  24.     
  25. /* Needs to be 2 wide so that I can always tell a 2 dimensional list from a normal text list. */
  26. #define minIconsPerRow             2
  27. #define ICONMinWindowWidth     (minIconsPerRow * listCellSizeH) + theScrollBar
  28. #define ICONMinWindowHeight listCellSizeV
  29.  
  30.  
  31.     typedef struct IconPickRec {
  32.         ParentHandle    father;                    /* Back ptr to dad             */
  33.         Str255                fName;                    /* Max 255 characters.         */         
  34.         WindowPtr            wind;                        /* Picker window         */
  35.         Boolean                rebuild;                /* Flag set to indicate that window should be rebuilt  */
  36.         Boolean                spare1;                    /* Not used here */
  37.         unsigned char    windowType;
  38.         ResType                theResType;            /* Type of the resource being picked or edited. */
  39.         short                    theResFile;            /* The home resfile of the window. */
  40.         short                    codeResID;            /* Resource ID of the RSSC resource containing the picker or editor. */
  41.         Handle                spare;                    /* Not used here */
  42.  
  43.         ResType                rType;                    /* Type for this picker     */
  44.         long                    rSize;                    /* size of a null resource     */
  45.         short                    minWindowWidth;    /* Use when the window is grown. */
  46.         short                    minWindowHeight;
  47.         ListHandle        instances;            /* List of instances         */
  48.         short                    nInsts;                    /* Number of instances         */
  49.         unsigned char    viewBy;                    /* Current view type        */
  50.         Boolean                showAttributes;    /* Show attrs in window?    */
  51.         ResType                ldefType;                /* Which LDEF to use        */
  52.         MenuHandle        theViewMenu;        /* The picker view menu        */
  53.         long                    viewMenuMask;        /* Which items are enabled?    */
  54.         Cell                    cellSize;                /* Size for special view.    */
  55.         MenuHandle        iconMenu;                /* Our menu */
  56.     } IconPickRec;
  57.     
  58.     typedef    IconPickRec    *IconPickPtr;
  59.     typedef    IconPickPtr    *IconPickHandle;
  60.  
  61. /* Used only for editors. */
  62. pascal void EditBirth(Handle thing, ParentHandle dad)
  63. {
  64.     #pragma    unused (thing, dad)
  65. }
  66.  
  67. /* *********************************************************************************** */
  68.  
  69. pascal void PickBirth(ResType t, ParentHandle dad)
  70. {
  71.     IconPickHandle     pick;
  72.     IconPickPtr            p;                    /* temp ptr for *pick */
  73.     MenuHandle            theIconMenu;
  74.  
  75.     pick = (IconPickHandle)NewHandle(sizeof(IconPickRec));
  76.  
  77.     p = *pick;
  78.  
  79.     p->father = dad;                                     /* Back ptr to dad                                                                             */
  80.     p->rType = t;                                         /* Resource type that I understand                                             */
  81.     p->viewBy = viewBySpecial;                /* Special means we have our own LDEF to draw the icons */
  82.     p->ldefType = t;                                    /* Which LDEF do we use? */
  83.     p->cellSize.h = listCellSizeH;        /* Set the size of the cell.                                                        */
  84.     p->cellSize.v = listCellSizeV;
  85.     p->minWindowWidth = ICONMinWindowWidth;
  86.     p->minWindowHeight = ICONMinWindowHeight;
  87.  
  88.   // Setup the list and create the window.
  89.     if (!DoPickBirth(noColor, true, graphical2DPicker, ResEdID(), (PickHandle)pick))
  90.         DisposHandle ((Handle)pick);        // Error
  91.     else {
  92.         theIconMenu = GetMenu(iconMenuID);
  93.         DetachResource((Handle)theIconMenu);        // Get our own copy of the menu.
  94.         (*pick)->iconMenu = theIconMenu;
  95.         }
  96. }
  97. /* *********************************************************************************** */
  98.  
  99. /* Everything is taken care of for us by PickEvent. */
  100. pascal void DoEvent(EventRecord *evt, IconPickHandle pick)
  101. {
  102.     PickEvent(evt, (PickHandle)pick);
  103.     if (evt->what == activateEvt) {
  104.         if (evt->modifiers & activeFlag)
  105.             InsertMenu((*pick)->iconMenu, 0);
  106.         else
  107.             DeleteMenu(iconMenuID);
  108.         DrawMBarLater(false);
  109.         }
  110. }
  111.  
  112. /* *********************************************************************************** */
  113.  
  114. /* Everything is taken care of for us by PickInfoUp                                                                      */
  115. pascal void DoInfoUpdate(short oldID, short newID, PickHandle pick)
  116. {
  117.     PickInfoUp(oldID, newID, pick);
  118. }
  119.  
  120. /* *********************************************************************************** */
  121.  
  122. pascal Boolean IsThisYours (Handle thing, PickHandle pick)
  123.  
  124. {
  125.     #pragma    unused (thing, pick)
  126.     return false;
  127. }
  128.  
  129. /* *********************************************************************************** */
  130.  
  131. /* Everything is taken care of for us by PickMenu.                                                                        */
  132. pascal void DoMenu(short menu, short item, IconPickHandle pick)
  133. {
  134.     if (menu == iconMenuID) {
  135.         /* Do something with the menu */
  136.         }
  137.     else {
  138.         if ((menu == fileMenu) && (item == closeItem)) {
  139.             DeleteMenu(iconMenuID);
  140.             DrawMBarLater(false);
  141.             DisposHandle((Handle)(*pick)->iconMenu);
  142.             }
  143.         PickMenu(menu, item, (PickHandle)pick);
  144.         }
  145. }
  146.